<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015-5-23
 * Time: 13:36
 */

namespace doumiaoduo\layer;
use yii\base\Widget;

class LayerConfirmWidget extends Widget{

    public $button;

    public function init(){
        parent::init();
        if ($this->button === null) {
            $this->button= "['确定','取消']";
        }
    }

    public function run()
    {
        $view = $this->getView();
        LayerAsset::register($view);
        $js_str="
            var layout='<div class=".'"'."yx-warn yx-radius50".'"'."><h1>!</h1></div>';
            layer.config({
                extend: ['/skin/customskin/style.css'],
            });
           $(document).on('click','a[rel=record_item_confirm]',function(){
                var url=$(this).data('url');
                var title=$(this).text()!=''?$(this).text():'确认';
                layer.confirm(layout+'<p>'+$(this).data('message')+'</p>', {
                    title: title,
                    area: ['440px', '270px'],
                    skin: 'layui-confirm-customskin',
                    shift:1,
                    id:'layer-iframe',
                    btn: ".$this->button.",
                    yes: function(index, layero){
                      $.post(url,{},function(data){
                        layer.open({
                            content:data
                        })
                      });
                    }
                });
           })";
        $view->registerJs($js_str);
    }
}